<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    


    <script>
        //递归
        let sum = 1
        getRes(6)
        function getRes(num) {
            sum = sum * num
            num--
            if(num === 0) {
                return sum
            }
            getRes(num)
        }
        console.log(sum)

        let list = [
            {id:'1', pid:'',name:'小王'},
            {id:'2', pid:'',name:'小刘'},
            {id:'3', pid:'1',name:'小张'},
            {id:'4', pid:'1',name:'小赵'},
            {id:'5', pid:'2',name:'小钱'},
            {id:'6', pid:'3',name:'小钱'}
        ]
        //将数组和空字符作为参数传给函数
        list = getTree(list,'')

        function  getTree(arr, lpid) {
            //遍历函数筛选符合条件的  
            //第一轮 pid为''的   
            //第二轮 pid 等于 第一轮筛选元素的id 
            const arr1 = arr.filter(item => item.pid === lpid)
            //再次进行遍历  将对象元素的id作为参数传递
            arr1.forEach(itm => {
                itm.children = getTree(arr,itm.id)
            } )
            return arr1
        }
        console.log(list)



    </script>
</body>
</html>